<?php

require_once '../MMysql.php';

/**
 * Created by PhpStorm.
 * User: hcadmin
 * Date: 16/8/18
 * Time: 上午9:17
 */
class propertyfuction
{
    public function addemployee($employee_fullname,$employee_email,$employee_tel,$employee_wechat
    ,$employee_address,$resbonsible_city)
    {

        $mysql = new MMysql();
        return $mysql->insert('employees',array(
            'employee_fullname'=>$employee_fullname,
            'employee_email'=>$employee_email,
            'employee_tel'=>$employee_tel,
            'employee_wechat'=>$employee_wechat,
            'employee_address'=>$employee_address,
            'resbonsible_city'=>$resbonsible_city,
            'del_flag'=>0,
            'create_time'=>date("y-m-d",time())
        ));
    }

    public function editemployee($employee_fullname,$employee_email,$employee_tel,$employee_wechat
        ,$employee_address,$resbonsible_city,$employee_id)
    {
        $mysql = new MMysql();
        return $mysql
            ->where(array('employee_id'=>$employee_id))
            ->update('employees',array(
            'employee_fullname'=>$employee_fullname,
            'employee_email'=>$employee_email,
            'employee_tel'=>$employee_tel,
            'employee_wechat'=>$employee_wechat,
            'employee_address'=>$employee_address,
            'resbonsible_city'=>$resbonsible_city
        ));
    }

    public function deleteemployee($employee_id){

        $mysql = new MMysql();

        return $mysql->where(array('employee_id'=>$employee_id))->update('employees',array(
            'del_flag'=>1,
        ));
    }

    public function selectemployee($page,$rows)
    {

        $mysql = new MMysql();
        $res = $mysql
            ->where(array("del_flag"=>0))
            ->limit($page,$rows)
            ->order(array('employee_id'=>'desc'))
            ->select('employees');

        $count=$mysql->where(array("del_flag"=>0))->count('employees');

        $array=Array();
        $array["rows"]=$res;
        $array["total"]=$count;
        echo json_encode($array);
    }
}


$method =$_REQUEST["method"];

if($method=='list'){

    $d=new propertyfuction();

    return $d->selectemployee($_REQUEST["page"],$_REQUEST["rows"]);

}
else if($method=='add'){
    $d=new propertyfuction();

    echo $d->addemployee(
        $_REQUEST["employee_fullname"],$_REQUEST["employee_email"],$_REQUEST["employee_tel"],
        $_REQUEST["employee_wechat"],$_REQUEST["employee_address"],$_REQUEST["resbonsible_city"]);
}

else if($method=='edit'){
    $d=new propertyfuction();

    echo $d->editemployee(
        $_REQUEST["employee_fullname"],$_REQUEST["employee_email"],$_REQUEST["employee_tel"],
        $_REQUEST["employee_wechat"],$_REQUEST["employee_address"],$_REQUEST["resbonsible_city"]
    ,$_REQUEST["employee_id"]);
}
else if($method=='delete'){
    $d=new propertyfuction();

    echo $d->deleteemployee($_REQUEST["employee_id"]);
}